<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<body>
<script>
function chk(data){
	if(!data.name.value.trim()){
		$("#error").html("상품명을 입력하세요");
		return false;
	}else{
		$("#error").html("");
	}
	if(!data.price.value.trim()){
		$("#error").html("가격을 입력하세요");
		return false;
	}else if(isNaN(data.price.value)){
		$("#error").html("숫자를 입력하세요");
		return false;
	}else{
		$("#error").html("");
	}
	if(!data.brand.value.trim()){
		$("#error").html("제품명을 입력하세요");
		return false;
	}else{
		$("#error").html("");
	}
	if(!data.modelNo.value.trim()){
		$("#error").html("제품번호를 입력하세요");
		return false;
	}else{
		$("#error").html("");
	}
	if(!data.quantity.value.trim()){
		$("#error").html("수량을 입력하세요");
		return false;
	}else if(isNaN(data.quantity.value)){
		$("#error").html("숫자를 입력하세요");
		return false;
	}else{
		$("#error").html("");
	}
}

</script>
<form action="/droowa/product/modifyProduct.do" onsubmit="return chk(this)" method="post" encType="multipart/form-data">
<input type="hidden" name="id" value="${requestScope.product.id}">
<input type="hidden" name="del" value="${requestScope.product.del}">
<input type="hidden" name="picture" value="${requestScope.product.fileName}">

<h2 align="center">상품 수정</h2>
<table align="center">
	<tr>
		<td height="20" id="error" style="color: red;"></td>
	</tr>
</table>
<table>
	<tr align="center" bgcolor="#BDBDBD">
		<td width="90"></td>
		<td width="65">아이디</td>
		<td width="100">카테고리</td>
		<td>상품명</td>
		<td>가격</td>
		<td>제조사</td>
		<td>모델번호</td>
		<td>수량</td>
		<td>상세설명</td>
		<td>수정</td>
	</tr>
	<tr align="center">
		<td width="90" height="90">
		<c:choose>
			<c:when test="${requestScope.product.fileName!=null }">
				<img src="/droowa/product-img/${product.fileName}" style="width:90px; height=90px;">
			</c:when>
			<c:when test="${requestScope.product.fileName==null}">
				<img src="/droowa/product-img/No_image.jpg" style="width:90px; height=90px;">
			</c:when>	
		</c:choose>
		</td>
		<td>${requestScope.product.id}</td>
		<td>${requestScope.product.categoryName}</td>
		<td><input type="text" name="name" id="name" value="${requestScope.product.name}" style="width:90px;"></td>
		<td><input type="text" name="price" id="price" value="${requestScope.product.price}" style="width:90px;"></td>
		<td><input type="text" name="brand" id="brand" value="${requestScope.product.brand}" style="width:90px;"></td>
		<td><input type="text" name="modelNo" id="modelNo" value="${requestScope.product.modelNo}" style="width:90px;"></td>
		<td><input type="text" name="quantity" id="quantity" value="${requestScope.product.quantity}" style="width:40px;"></td>
		<td><input type="text" name="description" value="${requestScope.product.description}" style="width:340px;"></td>
		<td><input type="submit" value="수정"></td>
	</tr>
	<tr>
		<td align="center">사진 업로드</td>
		<td colspan="2">
			<input type="file" name="pic">
		</td>
	</tr>
</table>
</form>
</body>